﻿Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Design

<ToolboxItem(False)> <Designer(GetType(DialogWhiteBottomDesigner))> _
Public Class DialogWhiteBottom
    Private mLoading As Boolean = False

    Public Shadows ReadOnly Property Controls() As ControlCollection
        Get
            If mLoading = True Then Return MyBase.Controls
            Return pnlMain.Controls
        End Get
    End Property
#Region "Border Resizing"
#Region "Left"
    Dim np As Point
    Private Sub pnlL_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlL.MouseDown
        np = New Point(MousePosition.X, MousePosition.Y)
        CType(sender, Control).Capture = True
    End Sub
    Private Sub pnlL_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlL.MouseMove
        If CType(sender, Control).Capture = True Then
            Dim mp As Point = MousePosition
            Dim diff As New Point(np.X - mp.X, mp.Y - np.Y)

            Me.ParentForm.Size = New Size(Me.ParentForm.Size.Width + diff.X, Me.ParentForm.Size.Height)
            Me.ParentForm.Location = New Point(Me.ParentForm.Location.X - diff.X, Me.ParentForm.Location.Y)
            'Me.ResumeLayout()
            np = mp
        End If
    End Sub
    Private Sub pnlL_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlL.MouseUp
        CType(sender, Control).Capture = False
    End Sub
#End Region
#Region "Bottom Left"

    Private Sub pnlBL_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBL.MouseDown
        np = New Point(MousePosition.X, MousePosition.Y)
        CType(sender, Control).Capture = True
    End Sub
    Private Sub pnlBL_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBL.MouseMove
        If CType(sender, Control).Capture = True Then
            Dim mp As Point = MousePosition
            Dim diff As New Point(np.X - mp.X, mp.Y - np.Y)

            Me.ParentForm.Size = New Size(Me.ParentForm.Size.Width + diff.X, Me.ParentForm.Size.Height + diff.Y)
            Me.ParentForm.Location = New Point(Me.ParentForm.Location.X - diff.X, Me.ParentForm.Location.Y)
            'Me.ResumeLayout()
            np = mp
        End If
    End Sub
    Private Sub pnlBL_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBL.MouseUp
        CType(sender, Control).Capture = False
    End Sub
#End Region
#Region "Bottom"
    Private Sub pnlB_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlB.MouseEnter

    End Sub
#End Region
#Region "Bottom Right"

    Private Sub pnlBR_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBR.MouseDown
        np = New Point(MousePosition.X, MousePosition.Y)
        CType(sender, Control).Capture = True
    End Sub
    Private Sub pnlBR_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBR.MouseMove
        If CType(sender, Control).Capture = True Then
            Dim mp As Point = MousePosition
            Dim diff As New Point(mp.X - np.X, mp.Y - np.Y)

            Me.ParentForm.Size = New Size(Me.ParentForm.Size.Width + diff.X, Me.ParentForm.Size.Height + diff.Y)
            'Me.ParentForm.Location = New Point(Me.ParentForm.Location.X - diff.X, Me.ParentForm.Location.Y)
            'Me.ResumeLayout()
            np = mp
        End If
    End Sub

    Private Sub pnlBR_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlBR.MouseUp
        CType(sender, Control).Capture = False
    End Sub
#End Region
#Region "Right"
    Private Sub pnlR_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlR.MouseDown
        np = New Point(MousePosition.X, MousePosition.Y)
        CType(sender, Control).Capture = True
    End Sub

    Private Sub pnlR_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlR.MouseMove
        If CType(sender, Control).Capture = True Then
            Dim mp As Point = MousePosition
            Dim diff As New Point(mp.X - np.X, mp.Y - np.Y)
            Me.ParentForm.Size = New Size(Me.ParentForm.Size.Width + diff.X, Me.ParentForm.Size.Height)
            'Me.ResumeLayout()
            np = mp
        End If
    End Sub

    Private Sub pnlR_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlR.MouseUp
        CType(sender, Control).Capture = False
    End Sub
#End Region
#End Region

    'Private Sub DialogWhiteBottom_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded
    '    If mFinishedLoading = True Then
    '        Me.pnlMain.Controls.Add(e.Control)
    '    End If

    'End Sub



End Class


Friend Class DialogWhiteBottomDesigner
    Inherits ControlDesigner

    Private MyControl As DialogWhiteBottom

    Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
        MyBase.Initialize(component)

        'Record instance of control we're designing
        MyControl = DirectCast(component, DialogWhiteBottom)

        'Hook up events
        Dim s As ISelectionService = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
        Dim c As IComponentChangeService = DirectCast(GetService(GetType(IComponentChangeService)), IComponentChangeService)
        'AddHandler s.SelectionChanged, AddressOf OnSelectionChanged
        'AddHandler c.ComponentRemoving, AddressOf OnComponentRemoving
        AddHandler c.ComponentAdding, AddressOf OnAdding
        EnableDragDrop(True)
    End Sub

    Private Sub OnAdding(ByVal sender As Object, ByVal e As System.ComponentModel.Design.ComponentEventArgs)
        MsgBox("Added")
        'If e.Component.GetType.ToString.ToLower.Contains("colourbutton") = False Then
        '    Dim button As Windows.Forms.Button
        '    Dim h As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
        '    button = DirectCast(e.Component, Windows.Forms.Button)
        '    MyControl.Controls.Add(button)
        '    'MsgBox(e.Component.GetType.ToString)
        '    'Dim button As Windows.Forms.Button
        '    'Dim h As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
        '    'Dim dt As DesignerTransaction
        '    'Dim c As IComponentChangeService = DirectCast(GetService(GetType(IComponentChangeService)), IComponentChangeService)

        '    ''Add a new button to the collection
        '    'dt = h.CreateTransaction("Add Button")
        '    'button = DirectCast(h.CreateComponent(GetType(Windows.Forms.Button)), Windows.Forms.Button)
        '    'c.OnComponentChanging(MyControl, Nothing)
        '    'MyControl.Controls.Add(button)
        '    'c.OnComponentChanged(MyControl, Nothing, Nothing, Nothing)
        '    'dt.Commit()
        'End If
    End Sub

    Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
        Get
            Dim v As New DesignerVerbCollection()

            'Verb to add buttons
            v.Add(New DesignerVerb("&Message Me", AddressOf OnAddButton))

            Return v
        End Get
    End Property

    Private Sub OnAddButton(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox("Hi")
    End Sub
End Class